const dataModel = require("../models/data");

exports.publish = async (options) => {
    let databaseField = [
        "userId",
        "nickName",
        "sex",
        "nation",
        "birth",
        "height",
        "weight",
        "constellation", // 星座
        "education",
        "hometown",
        "familyType",
        "onlychild",
        "address",
        "maritalStatus",
        "jop",
        "jopType",
        "carHouse",
        "income",
        "contact",
        "desc",
        "myhope",
        "imgList",
        "status",
        "channel"
    ];

    for (let item in options) {
        if (!databaseField.includes(item)) {
            delete options[item];
            continue;
        }
        // 数组序列话
        if (Array.isArray(options[item])) {
            options[item] = JSON.stringify(options[item]);
        }
    }

    options.createTime = Date.now();
    console.log("xxxxx", options);

    await dataModel.publish(options);
};

exports.queryList = async (param) => {
    const result = await dataModel.queryList(param);
    return result;
};

/**
 * 查询我发布的帖子
 * @param {*} param
 * @returns
 */
exports.queryMyPublish = async (param) => {
    const result = await dataModel.queryMyPublish(param);
    return result;
};
